import java.io.*;
import java.util.*;

/*
 ID: ning yusui
 LANG: JAVA
 TASK: prefix
 */

public class prefix {


    public static final int BUFFER_SIZE = 200*1000+1;

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(new File("prefix.in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
                "prefix.out")));
        List<String> primitiveList = new ArrayList<String>();

        while (in.hasNext()) {
            String next = in.next();
            if (".".equals(next)) {
                break;
            } else {
                primitiveList.add(next);
            }
        }

        int longestPrefix = 0;
        boolean flags[] = new boolean[BUFFER_SIZE];
        flags[0]=true;
        StringBuilder sequenceBuffer = new StringBuilder(BUFFER_SIZE);
        while (in.hasNext()) {
            String newLine = in.next();
            sequenceBuffer.append(newLine);
        }
        String sequence = sequenceBuffer.toString();
        for (int index = 0; index <= sequenceBuffer.length(); index++) {
            if(flags[index]){
                longestPrefix = check(primitiveList, index, longestPrefix, flags, sequence);
            }
        }
        out.println(longestPrefix);
        out.flush();
        out.close();
    }

    private static int check(List<String> primitiveList, int index, int longestPrefix, boolean[] flags, String sequence) {
        for (String pri : primitiveList) {
            int endIndex = index + pri.length();
            if (sequence.startsWith(pri, index)) {
                flags[endIndex]=true;
                if(longestPrefix< endIndex){
                    longestPrefix = endIndex;
                }
            }
        }
        return longestPrefix;
    }

}
